package com.bbx.taxi.client.widget.Dailog;

import com.bbx.taxi.client.Util.IsActivityFinishUtils;
import com.bbx.taxi.official.R;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

/** 
 * @Path com.bbx.taxi.client.widget.Dailog.MyRejectDialog.java
 * @Author 严旭文
 * @Date 2016-1-20 下午6:35:50
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyRejectDialog extends Dialog implements
		android.view.View.OnClickListener {
	public interface onRejectClickLeftListener {
		public void onRejectClickLeft();
	}

	public interface onRejectClickRightListener {
		public void onRejectClickRight();
	}

	public onRejectClickLeftListener monRejectClickLeftListener;
	public onRejectClickRightListener monRejectClickRightListener;
	public LinearLayout layout_dailog;
	private TextView tv_title;
	private EditText et_reject;
	private Button btn_cencel, btn_confirm;
	private boolean cancelable = true;
    private Context context;
    private boolean isFinish=false;
	public MyRejectDialog(Context context) {
		super(context, R.style.Dialog_bocop);
		this.context=context;
		init();
	}

	private void init() {
		View contentView = View.inflate(getContext(), R.layout.dailog_reject,
				null);
		setContentView(contentView);
		tv_title = (TextView) findViewById(R.id.tv_title);
		btn_cencel = (Button) findViewById(R.id.btn_cencel);
		btn_confirm = (Button) findViewById(R.id.btn_confirm);
		layout_dailog = (LinearLayout) findViewById(R.id.layout_dailog);
		et_reject = (EditText) findViewById(R.id.et_reject);
		btn_cencel.setOnClickListener(this);
		btn_confirm.setOnClickListener(this);
		layout_dailog.setVisibility(View.GONE);
		this.setCancelable(false);
		contentView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (cancelable) {
					dismiss();
				}
			}
		});
	}

	@Override
	public void show() {
		if(!IsActivityFinishUtils.isActivityFinish(context)){
		super.show();
		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_in);
		layout_dailog.startAnimation(a);
		layout_dailog.setVisibility(View.VISIBLE);
		isFinish=false;
		}
	}

	@SuppressLint("NewApi")
	@Override
	public void dismiss() {
		if(!IsActivityFinishUtils.isActivityFinish(context)){
		if(isFinish)
		super.dismiss();
		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_out);
		layout_dailog.startAnimation(a);
		a.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation anim) {}
			
			@Override
			public void onAnimationRepeat(Animation anim) {}	
			@Override
			public void onAnimationEnd(Animation anim) {
				isFinish=true;
				dismiss();
			}
		});
		}

	}
	@Override
	public void setCancelable(boolean flag) {
		cancelable = flag;
		super.setCancelable(flag);
	}

	public void setTitle(String text) {
		if(text==null){
			tv_title.setVisibility(View.GONE);
		}
		else{
			tv_title.setVisibility(View.VISIBLE);
			tv_title.setText(text);
		}
		
	}
	public void setEditText(String text){
		et_reject.setHint(text);
	}
	public String getEditText(){
		return et_reject.getText().toString();
	}

	public void setLeftButtonText(String text) {
		btn_cencel.setText(text);
	}

	public void setRightButtonText(String text) {
		btn_confirm.setText(text);
	}

	public void setOnRejectClickLeftListener(onRejectClickLeftListener l) {
		monRejectClickLeftListener = l;
	}

	public void setOnRejectClickRightListener(
			onRejectClickRightListener l) {
		monRejectClickRightListener = l;
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_cencel:
			if (monRejectClickLeftListener != null)
				monRejectClickLeftListener.onRejectClickLeft();
			break;
		case R.id.btn_confirm:
			if (monRejectClickRightListener != null)
				monRejectClickRightListener.onRejectClickRight();
			dismiss();
			break;
		}

	}
}
